<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>登录&注册</title>
<link rel="stylesheet" href="css/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/loginandregister-style.css">
<link rel="stylesheet" href="admin-html/css/layer.css">
<link rel="stylesheet" href="admin-html/lib/layui/css/layui.css">
</head>
<body>
<div class="materialContainer">
	<div class="box">
		<div class="title">登录</div>
		<div class="input">
			<label for="name">用户名</label>
			<input type="text" name="name" id="name">
			<span class="spin"></span>
		</div>
		<div class="input">
			<label for="pass">密码</label>
			<input type="password" name="pass" id="pass">
			<span class="spin"></span>
		</div>
		<div class="button login">
			<button onclick="toLogin()">
				<span>登录</span>
				<i class="fa fa-check"></i>
			</button>
		</div>

		<a href="javascript:" class="pass-forgot">忘记密码？</a>
	</div>

	<div class="overbox">
		<div class="material-button alt-2">
			<span class="shape"></span>
		</div>
		<div class="title">注册</div>
		<div class="input">
			<label for="regname">用户名</label>
			<input type="text" name="regname" id="regname">
			<span class="spin"></span>
		</div>
		<div class="input">
			<label for="regpass">密码</label>
			<input type="password" name="regpass" id="regpass">
			<span class="spin"></span>
		</div>
		<div class="input">
			<label for="reregpass">确认密码</label>
			<input type="password" name="reregpass" id="reregpass">
			<span class="spin"></span>
		</div>
		<div class="button">
			<button onclick="toRegister()">
				<span>注册</span>
			</button>
		</div>
	</div>

</div>

<script src="js/jquery.min.js"></script>
<script src="js/loginAndregister.js"></script>
<script src="admin-html/lay/modules/layer.js"></script>
<script src="admin-html/lib/layui/layui.js"></script>
<script>
	function toLogin() {
		var msg = layer.msg('登陆中...', {icon: 16,time: 0});
		var phonenum = $("#name").val();
		var psword = $("#pass").val();
		var data={
				"phonenum":phonenum,
				"obuserpassword":psword
			};
		$.ajax({
			url: "http://www.longm.top:8080/lm/admin/userLogin",
			type: "post",
			dataType: 'json',
			headers:{'Content-Type':'application/json'},
			data: JSON.stringify(data),
			success: function (result) {
				console.log(JSON.stringify(result));
				if (result.code === 200) {
					layer.close(msg);
					window.location.href = "personalcenter.html";
					window.localStorage.setItem("token",result.data.token);
				} else {
					layer.close(msg);
					layer.msg(result["message"]);
				}
			}
		});
	}

	
	
	function toRegister() {
		var phonenum = $("#regname").val();
		var psword = $("#regpass").val();
		var repsword = $("#reregpass").val();
		var data={
			"phonenum":phonenum,
			"obuserpassword":psword,
			"confirePassword":repsword
		};	
		$.ajax({
			url: "http://www.longm.top:8080/lm/UserRegist",
			type: "post",
			contentType: "application/json",
			dataType: 'json',
			cache: true,
			async: false,
			data: JSON.stringify(data),
			success: function (result) {
				alert(result["message"]);
			},
			error: function (result) {
				alert(result["message"]);
			}
		});
	}
</script>
</body>
</html>